<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
	<div class="pc-year">
		<span class="up" onclick="$('#host_show_main_panel').panel('refresh', '${ctx}/show/date.do?id=${param['id']}&date=<fmt:formatDate value="${back}" type="date" pattern="yyyy-MM"/>-01');"></span>
		<span class="down" onclick="$('#host_show_main_panel').panel('refresh', '${ctx}/show/date.do?id=${param['id']}&date=<fmt:formatDate value="${next}" type="date" pattern="yyyy-MM"/>-01');"></span>
		<fmt:formatDate value="${searchDate}" type="date" pattern="yyyy年MM月"/>
	</div>
	<table class="calendar" width="100%" height="344px" cellpadding="0" cellspacing="0" bgcolor="#fff">
		<tr>
			<th class="red">星期日</th>
			<th>星期一</th>
			<th>星期二</th>
			<th>星期三</th>
			<th>星期四</th>
			<th>星期五</th>
 			<th class="red">星期六</th>                    	
		</tr>
		<c:forEach items="${calendar}" var="week">
		<tr>
			<c:forEach items="${week}" var="day">
			<td title="<fmt:formatDate value="${day}" type="date" pattern="yyyy-MM-dd"/>">
				<span class="day">
					<fmt:formatDate value="${day}" type="date" pattern="d"/>
				</span>
			</td>
			</c:forEach>
		</tr>
		</c:forEach>
	</table>
<script type="text/javascript">
var searchDate = "<fmt:formatDate value="${searchDate}" type="date" pattern="yyyy-MM"/>";
var today = "<fmt:formatDate value="${today}" type="date" pattern="yyyy-MM-dd"/>";
$(function(){
	$("table.calendar td[title^='" + searchDate + "']").each(function(){
		setDayStatus(searchDate, "open");
	})
	.append("<br /><br /><div name='info'>提供代养服务</div>")
	.find("span").css("color", "#FFFFFF");
	//获取已经禁用的日期
	$.getJSON("${ctx}/show/sevdate.do?id=${param['id']}&date=" + searchDate + "-01", function(res){
		for(var i=0;i<res.length;i++) {
			var sevDate = res[i];
			var beginDate = new Date(sevDate.disableBegan);
			var endDate = new Date(sevDate.disableEnd);
			while(beginDate <= endDate) {
				setDayStatus(beginDate.format("yyyy-MM-dd"), "close");
				beginDate.setDate(beginDate.getDate() + 1);
			}			
		}
	});
});

function setDayStatus(dateStr, status) {
	$(".calendar td[title^='" + dateStr + "']")
	.attr("status", status)
	.removeClass("org")
	.removeClass("blue").each(function(){
		if(status == "open") {
			$(this).addClass("blue").find(">div[name='info']").html("提供代养");
		} else if(status == "close") {
			$(this).addClass("org").find(">div[name='info']").html("不提供代养");
		}
	});
}
</script>
</body>
</html>